from frame.api.admin.base_admin import BaseAdmin


class MallManage(BaseAdmin):
    mall_url = "category/"

    def create(self, goods_name):
        """
        添加商品类目接口的实现
        :return:
        """
        # 请求数据
        create_data = {
            "name": goods_name,
            "keywords": "",
            "level": "L2",
            "pid": 0
        }
        # 定义请求参数
        create_req = {
            "url": self.mall_url + "create",
            "method": "POST",
            "json": create_data,
        }
        # 发起请求
        create_res = self.send_api(create_req)
        return create_res.json()

    def delete(self, goods_id, goods_name):
        """
        删除商品类目接口的实现
        :return:
        """
        # 请求数据
        del_data = {
            "id": goods_id,
            "name": goods_name,
            "keywords": "",
            "level": "L2"
        }
        del_req = {
            "url": self.mall_url + "delete",
            "method": "POST",
            "json": del_data,
        }
        # 发起请求
        del_res = self.send_api(del_req)
        return del_res.json()
